
$().ready(function() {
    validateRule();
});

$.validator.setDefaults({
    submitHandler : function() {
        save();
    }
});

function save() {
    $.ajax({
        cache : true,
        type : "POST",
        url : "/sys/centrePhoto/addCentrePhoto",
        data : {
            "typeId": $("#typeId option:selected").val(),
            "photoName": $("#photoName").val(),
            "centreId": $("#centreId").val(),
            "thumb": $("#thumb").val(),
            "sort": $("#sort").val(),
            // "content": UE.getEditor('content').getContent(),
            "isDelete": $('input[name="isDelete"]:checked').val(),
            "photoDesc": UE.getEditor('photoDesc').getAllHtml()
        },// 你的formid
        async : false,
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                if (data.msg) {
                    parent.layer.alert(data.msg)
                }else {
                    window.location.href = "/";
                }
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#form").validate({
        rules : {
            typeId : {
                required : true
            },
            photoName : {
                required : true
            },
            thumb : {
                required : true
            }
        },
        messages : {
            typeId : {
                required : icon + "类型不能为空！"
            },
            photoName : {
                required : icon + "名称不能为空！"
            },
            thumb : {
                required : icon + "图片不能为空！"
            }
        }
    })
}


